package com.altran.mirth.migration.v211;

import java.util.ArrayList;

/**
 * Project :  Mirth
 * Author :   Altran
 *
 * Copyright (C) 2011 - Altran 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */

public class DeprecatedFunction extends Occurency{

	String deprecatedPattern;
	String newPattern;	
	
	public final static String DEPRECATED_FUNCTION_1 = "ChannelController.getInstance().getChannelName(channelId)";
	public final static String NEW_FUNCTION_1 		 = "ChannelController.getInstance().getDeployedChannelById(channelId).getName()";
	
	public final static String DEPRECATED_FUNCTION_2 = "ChannelController.getInstance().getChannelId(";
	public final static String NEW_FUNCTION_2 		 = "ChannelController.getInstance().getDeployedChannelByName(channelName).getId()";

	public final static String DEPRECATED_FUNCTION_3 = "router.routeMessage(";
	public final static String NEW_FUNCTION_3 		 = "router.routeMessage(channelName, message, useQueue)";
	
	public final static String DEPRECATED_FUNCTION_4 = "router.routeMessageByChannelId(";
	public final static String NEW_FUNCTION_4 		 = "router.routeMessageByChannelId(channelId, message, useQueue)";
	
	public final static String DEPRECATED_FUNCTION_5 = "Entities.getInstance()";
	public final static String NEW_FUNCTION_5 		 = "XmlUtil";
	
	public final static String DEPRECATED_FUNCTION_6 = "${encoder.encode()}";
	public final static String NEW_FUNCTION_6 		 = "${XmlUtil.encode()}";
	
	public final static String DEPRECATED_FUNCTION_7 = "SerializerFactory.getHL7Serializer()";
	public final static String NEW_FUNCTION_7 		 = "SerializerFactory.getHL7Serializer(true, false, false)";

	public String getResults(){
		int nbReplacement = 0;
		int nbToReplace = 0;
		if ( isReplaceable() ) 
			nbReplacement = getNumberOfOccurency();
		else
			nbToReplace = getNumberOfOccurency();
		return "	#"+this.getID()+" - "+this.getName()+"	Replaced : "+nbReplacement+"	To be Replaced : "+nbToReplace;
	}

	
	public static ArrayList<DeprecatedFunction> loadAllFunctions(){
		ArrayList<DeprecatedFunction> listOfDeprecated = new ArrayList<DeprecatedFunction>();

		DeprecatedFunction func = new DeprecatedFunction();
		func.setID(1);
		func.setName("getChannelName");
		func.setDeprecatedPattern(DEPRECATED_FUNCTION_1);
		func.setNewPattern(NEW_FUNCTION_1);
		func.setReplaceable(true);
		listOfDeprecated.add(func);

		func = new DeprecatedFunction();
		func.setID(2);
		func.setName("getChannelID");
		func.setDeprecatedPattern(DEPRECATED_FUNCTION_2);
		func.setNewPattern(NEW_FUNCTION_2);
		func.setReplaceable(false);
		listOfDeprecated.add(func);

		func = new DeprecatedFunction();
		func.setID(3);
		func.setName("routeMessage");
		func.setDeprecatedPattern(DEPRECATED_FUNCTION_3);
		func.setNewPattern(NEW_FUNCTION_3);
		func.setReplaceable(false);
		listOfDeprecated.add(func);

		func = new DeprecatedFunction();
		func.setID(4);
		func.setName("routeMessageByChannelId");
		func.setDeprecatedPattern(DEPRECATED_FUNCTION_4);
		func.setNewPattern(NEW_FUNCTION_4);
		func.setReplaceable(false);
		listOfDeprecated.add(func);

		func = new DeprecatedFunction();
		func.setID(5);
		func.setName("Entities");
		func.setDeprecatedPattern(DEPRECATED_FUNCTION_5);
		func.setNewPattern(NEW_FUNCTION_5);
		func.setReplaceable(true);
		listOfDeprecated.add(func);

		func = new DeprecatedFunction();
		func.setID(6);
		func.setName("Encoder");
		func.setDeprecatedPattern(DEPRECATED_FUNCTION_6);
		func.setNewPattern(NEW_FUNCTION_6);
		func.setReplaceable(true);
		listOfDeprecated.add(func);

		func = new DeprecatedFunction();
		func.setID(7);
		func.setName("SerializerFactory");
		func.setDeprecatedPattern(DEPRECATED_FUNCTION_7);
		func.setNewPattern(NEW_FUNCTION_7);
		func.setReplaceable(true);
		listOfDeprecated.add(func);

		
		return listOfDeprecated;
	}
	
	/**
	 * @return the deprecatedPattern
	 */
	public String getDeprecatedPattern() {
		return deprecatedPattern;
	}
	/**
	 * @param deprecatedPattern the deprecatedPattern to set
	 */
	public void setDeprecatedPattern(String deprecatedPattern) {
		this.deprecatedPattern = deprecatedPattern;
	}
	/**
	 * @return the newPattern
	 */
	public String getNewPattern() {
		return newPattern;
	}
	/**
	 * @param newPattern the newPattern to set
	 */
	public void setNewPattern(String newPattern) {
		this.newPattern = newPattern;
	}
}
